from django.contrib import admin
from .models import *



@admin.register(Resource)
class ResourceAdmin(admin.ModelAdmin):
    list_display = ('title', 'file_type', 'category', 'download_count', 'created_date')
    list_filter = ('file_type', 'category')
    readonly_fields = ('download_count',)

    fieldsets = (
        ('文件配置', {
            'fields': ('file', 'file_type', 'category','tags'),
            'classes': ('collapse',),
            'description': '文件相关配置（下方可管理关联标签）'
        }),
        ('基础信息', {
            'fields': ('title', 'desc', 'content', 'image','author','articles'),
            'description': '资源的基本文字信息'
        }),

        ('统计信息', {
            'fields': ('download_count','is_public','created_date','modified_date'),
            'classes': ('grp-collapse grp-closed',)
        }),
    )


@admin.register(FavSite)
class FavSiteAdmin(admin.ModelAdmin):
    list_display = ('name', 'user', 'site_url', 'is_public','category')
    list_filter = ('is_public', 'user')
    search_fields = ('name', 'site_url')
    fieldsets = (
        ('基本信息', {
            'fields': ('name', 'user', 'desc', 'category', 'icon','image', 'is_public')
        }),
        ('网站地址', {
            'fields': ('site_url',)
        })
    )
@admin.register(Tool)
class ToolAdmin(admin.ModelAdmin):
    list_display = ('name', 'is_official', 'programming_language', 'rank')
    list_filter = ('is_official', 'programming_language')
    search_fields = ('name', 'desc')
    fieldsets = (
        ('基本信息', {
            'fields': ('name', 'desc', 'category', 'route','link' )
        }),
        ('展示信息', {
            'fields': ('image', 'programming_language')
        }),
        ('状态信息', {
            'fields': ('is_official', 'rank')
        })
    )
